/**
 * @description: 路由配置
 * @author: meidusa
 * @date: 2025-09-29
 */

import { createBrowserRouter, Navigate } from "react-router";
import type { RouteObject } from 'react-router';
import { lazy } from "react";

const LoginPage = lazy(() => import("../pages/login/index"));
const Home = lazy(() => import("../pages/home/index"));
const Workbench = lazy(() => import("../pages/workbench/index"));
const Layouts = lazy(() => import("../layouts/index")); // Layouts 组件

type AppRouteObject = RouteObject & {
    meta?: {
        title: string;
    };
    children?: AppRouteObject[];
};

// 路由配置
const routes: AppRouteObject[] = [
    {
        path: "/",
        element: <Navigate to="/login" replace />,
    },
    {
        path: "/login",
        Component: LoginPage,
    },
    {
        path: "/",
        element: <Layouts />,
        children: [
            {
                path: "workbench",
                Component: Workbench,
                meta: { title: "工作台", icon: "icon-gongzuotai" },
            },
            {
                path: "home",
                Component: Home,
                meta: { title: "首页", icon: "icon-gongzuotai" },
                children: [
                    {
                        path: "home1",
                        Component: Home,
                        meta: { title: "首页子", icon: "icon-gongzuotai" },
                    },
                ],
            },
            {
                path: "home2",
                Component: Home,
                meta: { title: "首页2", icon: "icon-gongzuotai" },
            }
        ],
    },
];


// 生成路由器
const router = createBrowserRouter(routes);
export default router;